<?php
/**
 ** added by lss@2017/07/14
 ** 设置生成第一次推荐计划
**/
//die('already done');
set_time_limit(0);
date_default_timezone_set("PRC");
include('./db_config.php');

$type = 20; //北京赛车对应数据库中的dat_type
//1.连接数据库->pdo方式
$db_pdo_link = pdo_write_read_link();

//2.获取公式
$file_url = 'algo_data.txt';
$algo_data = file_get_contents($file_url);
if(!empty($algo_data))
{
	$algo_data = unserialize($algo_data);
}else
{
	$sql = "select `algo_id` from  pk10_referral_algo";
	$algo_result = $db_pdo_link->query($sql);
	$algo_data = $algo_result->fetchAll(PDO::FETCH_ASSOC);
	if(count($algo_data)>=0)
	{
		file_put_contents($file_url,serialize($algo_data));
	}
}

if(!is_array($algo_data) || empty($algo_data))
{
	exit("获取公式失败");	
}

//3.定义计划种类
$guess_type_array = array('gjw','yjw','jjw','sjw','wjw','ljw','qjw','bjw','njw','tjw','q2zx','q3zx','gyhz','gyhzdx','gyhzds');

//4.获取最新一期的开奖期号
$yestoday_time = strtotime("-2 day"); //这个后续需要改日期
$last_exp_result = $db_pdo_link->query("select dat_id,dat_open_time,dat_expect from `lot_data` where dat_type='{$type}' and dat_open_time>='{$yestoday_time}' order by dat_id desc limit 1");
$last_exp = $last_exp_result->fetch(PDO::FETCH_ASSOC);
$first =  $last_exp['dat_expect'];
$last = $last_exp['dat_expect']+2;

//5.写入数据
foreach($algo_data as $algo_single) //1000个公式循环
{
	echo "php set_pk10_first_single.php  {$algo_single["algo_id"]}  {$first}  {$last}";
	//echo '<br/>';
	//continue;
	$last_line = system("php set_pk10_first_single.php {$algo_single["algo_id"]} {$first} {$last}",$retval);	

}

?>
